/**
 *
 * Module        : Loc (Lines of code)
 * Authors       : Ben Kwint & Arie van der Veek
 * Date          : November 8th 2011
 * Description   : Calculates the number of lines of code within a java
 *                 project. This means that it takes all lines that are not
 *                 empty and are not only comment. This means that lines that 
 *                 contain both code and comment are counted as a line of code 
 *
 */
module Metrics::Loc

import IO;
import String;
import Constants;
import List;

import Metrics::Regular::CommentLines;
import Metrics::Regular::EmptyLines;
import InOut::Input;

/* 	This module calculates the lines of code of source code.
	The definition of Lines Of Code is: All lines of source code that are not
	comment or blank lines.
*/
public int countLinesOfCode(list[str] lines){
  int nrOfLines = size(lines);
  
  for( line <- lines)
  { // substract the empty lines and the single comment lines with no prepending code, only whitespace
    // use this loop instead of the premade function to save looping through
    // the file multiple times
    nrOfLines -= (isEmptyLine(line)) ? 1: 0;
    nrOfLines -= (isSingleCommentLine(line)) ? 1 : 0;
  }
  nrOfLines -= MultiLineComment(lines);
  
  return nrOfLines;
}

public int countLOCForProject(loc l)
{
	return (0 | it + countLinesOfCode(readFileLines(fileLoc)) | fileLoc <- getFileList(l, ".java"));
}